#!/usr/bin/env python
import os,sys
def variableset():
    #set the default value.
    global nnme, searchway, path
    nnme = ""
    searchway = "gst"
    path = os.getenv( "HOME" ) + os.sep + "CD"
    print 'OK!'
def readarguments():
#    global nnme     #here regive a value for variable, have to use global.
    #another way to return the variable's value
    if len(sys.argv) == 1:
        nnme = "None"
        return nnme
    else:
        nnme = sys.argv[1]
        return nnme
    print '"'+nnme+'"'
def searchviagst():
    print nnme
    if nnme == "None":     #check the parameter.
        print "Didn't input the keyword, use blank for default."
        os.system("gnome-search-tool --contains=text --path=" + path + " --sortby=name --descending ")
    elif nnme != "":
        print "Search: ",
        print nnme+"*"
        shtext = "gnome-search-tool --contains="+nnme+" --path=" + path + " --sortby=name --descending --start"      #shtext is the command to call the gnome-search-tool with the arguments, nnme is the keyword of the searching, they are all strings.
        os.system(shtext)     #call the outside command - gnome-search-tool, use it for searching.
    else:
        print 'variable error!,@(nnme)'
def main():
    global nnme         #here regive a value for variable, have to use global.
    variableset()
    nnme = readarguments()      #use return to return the nnme's value.
    if searchway == 'gst':
        searchviagst()
    elif searchway == 'search':
        search()
    else:
        print 'search way error!\nNow Exit!'
        sys.exit(0)
if __name__ == "__main__":
    print 'program stat!'
    main()
    print "Finish!\nNow_Exit"       #tell the user no exit. \n men
    sys.exit(0)
